#ifndef CONFIG_MECRO_H
#define CONFIG_MECRO_H


/*===========================[Includes]======================================*/
#include <stdio.h>
#include <stdint.h>

#include <sys/time.h>
#include <time.h>

#include "macro_overload.h"



/*===========================[Defines]=======================================*/

/**>***** 节点 配置参数 ********/
/**> 结构体类型名 */
#define CONFIG_INFO_TYPE(dev_type)   info_conf_##dev_type##_t
/**> 变量名 */
#define DEV_CONFIG_INFO(dev_type)   dev_type##_info_config



/**> ******节点 实时参数 ********/
/**> 结构体名 */
#define RT_DATA_TYPE(dev_type)   rt_data_##dev_type##_t
/**> 变量名 */
#define DEV_RT_DATA(dev_type)   dev_type##_rt_data


/** 节点 操作函数类型 变量名 */
#define OP_FUNC_IRF(dev_type)   dev_type##_op_irf

#define OP_FUNC_INIT(dev_type)      func_##dev_type##_Init
#define OP_FUNC_RESET(dev_type)     func_##dev_type##_Reset
#define OP_FUNC_IO_CTR(dev_type)    func_##dev_type##_IOCtr
#define OP_FUNC_TIMING_REQUEST(dev_type)   func_##dev_type##_TimingRequest
#define OP_FUNC_PROTPARSE(dev_type) func_##dev_type##_ProtParse







/** 链表名称 */


#define LIST_NODE_TYPE(type_name)        list_##type_name##_t

#define LIST_FREE(type_name)             list_free_##type_name
#define LIST_WRITE(type_name)            list_write_##type_name
#define LIST_READ(type_name)             list_read_##type_name
#define LIST_DELETE(type_name)           list_delet_##type_name
#define LIST_DELETE_SOME(type_name)      list_delet_some_##type_name


#ifndef TRUE
#define TRUE    1
#endif


#ifndef FLASE
#define FLASE   0 
#endif


#ifndef ERROR
#define ERROR   -1 
#endif

/*===========================[Macros]========================================*/

#define ARRY_SIZE(arry)    (sizeof(arry)/sizeof(arry[0]))

#define debug_log(format, ...)  do{printf(format, ##__VA_ARGS__);}while (0)


#define info_log(format, ...)                                           \
                do{                                                     \
                    printf("\n---%s: line: %d----\n", __FILE__, __LINE__); \
                    printf(format, ##__VA_ARGS__);                      \
                    printf("---------------------------------------\n");\
                }while (0)


#define error_log(format, ...)                                           \
        do{                                                              \
            printf("\n+++++++++++++++ Error log +++++++++++++++++++\n"); \
            file_name_print(__FILE__);                                   \
            line_print(__LINE__);                                        \
            printf("[error]:"); printf(format, ##__VA_ARGS__);           \
            printf("\n+++++++++++++  Error log end +++++++++++++++\n\n");\
            CSV_CONFIG_ERR_SAVE(format, ##__VA_ARGS__);                  \
        }while (0)



/**> 配置文件错误写入路径 */
#define ERR_INFO_FILE_DIR    "src/config/err_info.txt"
/**> 错误写入 */
#define CSV_CONFIG_ERR_SAVE(format, ...)\
        do{\
            FILE *err_file = fopen(ERR_INFO_FILE_DIR, "a");\
            fprintf(err_file, "\n======== start ========\n");\
            fprintf(err_file, "[time]: %s", get_candlt());\
            fprintf(err_file, "[file name]: %s\n",__FILE__);\
            fprintf(err_file, "[line]: %d\n",__LINE__);\
            fprintf(err_file, format, ##__VA_ARGS__);\
            fprintf(err_file, "\n======== end ========\n");\
            fclose(err_file);\
        }while (0)
                               
/**
 * @brief 断言
 * 
 */
#define ASSERT_PARAM(expr) \
        do{                                                                    \
            (expr) ? (void)0 : assert_failed((const char *)__FILE__,__FUNCTION__,  __LINE__ );\
        }while (0)





/*===========================[Global Prototypes]=============================*/

void assert_failed(const char* _file_, const char* _function_, int _line_);

void file_name_print(const char* _file_);
void line_print(int _line_);


uint64_t get_century_seconds();
char* get_candlt();




#endif